// pages/user/index.js
Page({
  data: {
    userInfo: {},
    baseURL: 'http://43.139.97.111:8080',
  },
  onShow() {
    const userinfo = wx.getStorageSync("userInfo");
    this.setData({
      userInfo: userinfo
    });
    this.getAddress();
  },

  //获取地址
  getAddress: function (e) {
    var _this = this;
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    wx.request({
      url: 'http://43.139.97.111:8080/address/queryByUserId?userId=' + _this.data.userInfo.userId,
      method: 'GET',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res.data.data);
        if (res.statusCode == 200) {
          _this.setData({

          })
        }
        wx.setStorageSync('addressList', res.data.data)
        wx.hideLoading()
      }
    })
  },
  deleteUser(){
    var _this=this
    if(_this.data.userInfo!=''){
      wx.showModal({
        title: '提示',
        content: '您确定退出登录吗',
        success (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            wx.removeStorage({
              key: 'userInfo',
              success (res) {
                console.log(res)
              }
            })
        
            wx.navigateTo({
              url: '/pages/login/login',
              success: (result) => {},
              fail: (res) => {},
              complete: (res) => {},
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }else{
      wx.navigateTo({
        url: '/pages/login/login',
        success: (result) => {},
        fail: (res) => {},
        complete: (res) => {},
      })

    }
   

  }
})